<!DOCTYPE html>
<html>
<head>
	<title>定位</title>
</head>
<body>
	<div id="demo"></div>
	<script>
		
	var x=document.getElementById("demo");
	getLocation();
	function getLocation()
	  {
	  if (navigator.geolocation)
	    {
	   		 navigator.geolocation.getCurrentPosition(showPosition);
	    }
  		else{
  			alert("不能用谷歌定位");
  			x.innerHTML="Geolocation is not supported by this browser.";
  		}
	  }
	function showPosition(position)
	  {

	  	for (var posi in position ) {
	  		for (var i in position[posi]) {
	  		 	alert(position[posi][i]);
	  		 } 
	  	}

	  	alert(JSON.stringify(position.coords));
	  	x.innerHTML="Latitude: " + position.coords.latitude +
	 	 "<br />Longitude: " + position.coords.longitude;
	  }
</script>
</body>
</html>